package column


import (
	"github.com/treelab/updatecolumn/models"
)

  func instanceType() int32 {
    return models.Rating
  }

  async updateColumn(
    command: UpdateColumn_v2,
    o: CommonOptions,
    helper: { rows?: Row[]; columnCopy?: Column; referenceColumns?: Column[]; userGroup?: any },
  ) {
    await super.updateColumn(command, o, helper);

    const { column, columnConfig } = command;
    const { ratingMax, ratingStyle } = columnConfig as RatingColumnConfig;

    column.ratingMax = ratingMax;
    column.ratingStyle = ratingStyle;
    return this;
  }

  deleteColumnEdges(command: UpdateColumn_v2, o: CommonOptions) {
    const { column } = command;
    o.delQuads.push(...this.dgraphHelperService.getRemoveEdgeQuads(column.uid!, ['ratingMax', 'ratingStyle']));
    return this;
  }

  public hasNothingToUpdate(command: UpdateColumn_v2) {
    const { column } = command;
    const ratingColumnConfig = command.columnConfig as RatingColumnConfig;
    return (
      column.columnType === this.instanceType &&
      column.ratingMax === ratingColumnConfig.ratingMax &&
      column.ratingStyle === ratingColumnConfig.ratingStyle
    );
  }

  async convertColumn(
    command: UpdateColumn_v2,
    o: CommonOptions,
    helper: { rows?: Row[]; columnCopy?: Column; referenceColumns?: Column[]; userGroup?: any },
  ) {
    await this.defaultConvert({ command }, o, helper);
    return this;
  }

